<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String isShow = request.getParameter("isShow") == null ? "" : request.getParameter("isShow");
	String id = request.getParameter("id") == null ? "" : request.getParameter("id");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	boolean isAdd = "".equals(id);
    int flag = 0;
    if(!isAdd){
    	flag = 1;
    }
%>
<html>
	<head>
		<title><%=isAdd?"新建还款申请":"编辑还款申请" %></title>
		<script type="text/javascript" src="<%=contextPath %>/public/js/extend.js"></script>
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
		</style>
	<script type="text/javascript">
		$(function(){
			if('<%=flag%>' == 1){
		    	$('#ff').form('load','<%=contextPath%>/springMVC/finance/getEmployeeReimbursemeById?id=<%=id%>');
			}else{
				$("#operation_date").datebox('setValue',getTodaySecond());
			}
		});
		function addGDAdvances(obj){
			//自动提交数据
				var money = $("#reimbursement").numberbox("getValue");
				var operation_date=$("#operation_date").datebox('getValue');
				var remark = encodeURIComponent($('#remark').val());
				var loan_id = $('#loan_id').val();
				var param="&money="+money+"&operation_date="+operation_date+"&remark="+remark+"&loan_id="+loan_id+'&reimbursement='+money;
				$(obj).hide();
				$.ajax({
					type:'POST',
					<%=isAdd?"url:'"+contextPath+"/springMVC/finance/addEmployeeReimburseme',":"url:'"+contextPath+"/springMVC/finance/updateEmployeeReimburseme?id="+id+"',"%>
					data:param,
					dataType:'json',
					success:function(rtJson){
						if(rtJson.rtState == '0'){
							eval('window.opener.<%=callback%>();');
							window.close();
						}
						else{
							$.messager.alert("提示",rtJson.rtMsrg);
						}
						$(obj).show();
					}
				});
		}
	    function choseLoan(){
	    	openDialogResize("<%=contextPath %>/springViews/finance/choseEmployeeLoan.jsp","员工借款单选择",1000, 800);
	    	
	    }
	    function rtCallBackEmployeeSet(loan_id,employee_name,loan_money){
			 jQuery("#loan_id").val(loan_id);
		     jQuery("#employee_name").val(employee_name);
		     jQuery("#loan_money").numberbox("setValue",loan_money);
		}
	</script>
	</head>
	<body>
		<div style="width: 97%;padding-left:10px">
		<form id="ff">
			<table  style="border-collapse: collapse;" width="100%" border="1px" bordercolor="#0eb83a">
			<tr>
					<td align="right" class="td1" nowrap>借款人：</td>
					<td class="td2" nowrap  >
						<input type="hidden"  id="loan_id" name="loan_id"/>
						<input id="employee_name" name="employee_name" readOnly onclick="choseLoan();" placeholder="借款单选择"/>
						<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:false" onclick="choseLoan();"></a>		
					</td>
					<td align="right" class="td1" nowrap >申请日期：</td>
					<td class="td2" nowrap  >
						<input  id="operation_date" name="operation_date" class="easyui-datebox" data-options="required:true">
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>借款金额：</td>
					<td class="td2" nowrap >
							<input type="text" id="loan_money" name="loan_money" class="easyui-numberbox" data-options="required:true,min:0,precision:2"  readOnly />
					</td>
					<td align="right" class="td1" nowrap>还款金额：</td>
					<td class="td2" nowrap >
							<input type="text" id="reimbursement" name="reimbursement" class="easyui-numberbox" data-options="required:true,min:0,precision:2"  />
					</td>
				</tr>
				<tr>
					<td align="right" class="td1" nowrap>摘要：</td>
					<td class="td2"  colspan='3'>
						<textarea id="remark" name="remark"  style="height:100%;width:99%" rows="6"></textarea>
					</td>
				</tr>
						   <%if(!"1".equals(isShow)){ %>
				<tr>
					<td align="right" class="td1" nowrap></td>
					<td class="td2" nowrap colspan='3'>
						<div align="left">
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:false" onclick="addGDAdvances(this);">提交</a>
							<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:false" onclick="javascript:window.close();">关闭</a>
						</div>
					</td>
				</tr>
				<%} %>
			</table>
			</form>
		</div>
		
	</body>
</html>